package com.usian.user.service.impl;

import com.github.pagehelper.PageInfo;
import com.usian.common.dto.CompeDto;
import com.usian.common.dto.CompetitionDto;
import com.usian.common.pojo.Compe;
import com.usian.common.pojo.Que;
import com.usian.common.pojo.Question;
import com.usian.common.pojo.Team;
import com.usian.common.vo.PageResponseResult;
import com.usian.common.vo.ResponseResult;
import com.usian.user.feign.CompetitionFeign;
import com.usian.user.service.CompetitonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompetitonServiceImpl implements CompetitonService {
    
    @Autowired
    CompetitionFeign competitionFeign;
    @Override
    public ResponseResult getCompetitionList(CompetitionDto competitionDto) {
        PageInfo<Compe> compePageInfo = competitionFeign.getCompetitionList(competitionDto);
        PageResponseResult responseResult = new PageResponseResult();
        responseResult.setCurrentPage(competitionDto.getCurrentPage());
        responseResult.setPageSize(competitionDto.getPageSize());
        responseResult.setTotal((int) compePageInfo.getTotal());
        responseResult.setData(compePageInfo.getList());
        return responseResult;
    }

    @Override
    public ResponseResult getCompetitionById(Integer compeId) {
        Compe compe = competitionFeign.getCompetitionById(compeId);
        return ResponseResult.okResult(compe);
    }

    @Override
    public ResponseResult addMember(Integer compeId, Integer userId) {
        Boolean result = competitionFeign.addMember(compeId,userId);
        return ResponseResult.okResult(result);
    }

    @Override
    public ResponseResult getTeam() {
        List<Team> teamList = competitionFeign.getTeam();
        return ResponseResult.okResult(teamList);
    }

    @Override
    public ResponseResult startCompe(Integer compeId) {
        Compe compe = competitionFeign.startCompe(compeId);
        System.out.println("================="+compe);
        return ResponseResult.okResult(compe);
    }

    @Override
    public ResponseResult insertHistory(Integer compeId, Integer queId, Integer answerId) {
        competitionFeign.insertHistory(compeId,queId,answerId);
        return ResponseResult.okResult(true);
    }

    @Override
    public ResponseResult selectAnswerById(Integer compeId, Integer queId) {
        Integer ansId = competitionFeign.selectAnswerById(compeId,queId);
        return ResponseResult.okResult(ansId);
    }

    @Override
    public ResponseResult getQue(Integer compeId, Integer queId) {
        Que que = competitionFeign.getQue(compeId,queId);
        return ResponseResult.okResult(que);
    }

    @Override
    public ResponseResult getCompeResult(CompeDto compeDto) {
        Compe compe = competitionFeign.getCompeResult(compeDto);
        return ResponseResult.okResult(compe);
    }

    @Override
    public ResponseResult judgeAnswer(Integer compeId) {
        List<Question> questionList = competitionFeign.judgeAnswer(compeId);
        return ResponseResult.okResult(questionList);
    }
}
